﻿using System;
using System.Text;

namespace UtilZ.Dotnet.Ex.Base
{
    /// <summary>
    /// Array辅助类
    /// </summary>
    public static partial class ArrayEx
    {

#if NET4_0

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T[] Empty<T>()
        {
            return new T[0];
        }

#endif

        /// <summary>
        /// 向数组中填充指定值
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="array">数组</param>
        /// <param name="value">填充值</param>
        /// <param name="startIndex">起始索引</param>
        /// <param name="count">填充数量</param>
        /// <exception cref="ArgumentNullException">数组为null异常</exception>
        public static void Fill<T>(T[] array, T value, int startIndex, int count)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            int end = startIndex + count;
            for (int i = startIndex; i < end; i++)
            {
                array[i] = value;
            }
        }

        /// <summary>
        /// 向数组中填充指定值
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="array">数组</param>
        /// <param name="value">填充值</param>
        /// <exception cref="ArgumentNullException">数组为null异常</exception>
        public static void Fill<T>(T[] array, T value)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = value;
            }
        }

    }

}
